ihelpuoo.namespace("ihelpuoo.widget.error");

ihelpuoo.widget.error.shellPattern = "weboo.pattern.error.ErrorShell";
ihelpuoo.widget.error.itemPattern = "weboo.pattern.error.ErrorItem";

ihelpuoo.widget.error.getErrorView = function()
{
	var v = ihelpuoo.widget.getView("ihelpuoo.widget.error");
	if(null==v)
		v = new ihelpuoo.widget.error.ErrorView(); 
	return v;
}

ihelpuoo.widget.error.ErrorView = function()
{
	this.view = new ihelpuoo.widget.View(document.body
										,ihelpuoo.widget.error.shellPattern);
	this.name = "ihelpuoo.widget.error";
	this.oArena = null;
	this.oTitle = null;
	this.oOk = null;
	ihelpuoo.widget.registerView2(this);
}

ihelpuoo.widget.error.ErrorView.prototype
=
{
	draw : function(errors)
	{
		if(this.view.isNeverBeDrawn())
		{
			this.view.preparePattern();
			this.oArena = this.view.getElement("arena");
			this.oTitle = this.view.getElement("title");
			this.oOk = this.view.getElement("ok");
			this.view.addEvent("ok","click",this.onOK);
		}
		this.clear();
		this.view.shell.style.zIndex=2000;
		this.display();
		
		ihelpuoo.dom.autoSetObject(this.oTitle,errors.status);
		 
		if(null!=errors && errors.list.length>0)
		{
			for(var i=0;i<errors.list.length;i++)
			{
				var v = new ihelpuoo.widget.error.ErrorItemView(this.oArena);
				v.draw(errors.list[i]);					
			}
		}
		
		ihelpuoo.widget.GC.moveToCentre(this.view.shell,document.body);
		
		var t = ihelpuoo.widget.GC.getTop(this.view.shell);
		if(t > 150)
			this.view.shell.style.top = t - 150;
		if(ihelpuoo.isDebugEnabled())
		{	
			var r = ihelpuoo.widget.GC.getRect(this.view.shell);
			ihelpuoo.debug(r.dump());
		}
	}
	
	,
	display: function()
	{
		this.view.display();
		this.oOk.focus();
	}
	
	,hide: function()
	{
		if(this.oOk) this.oOk.blur();
		this.view.hide();
	}
	
	,
	clear: function()
	{
		if(null!=this.oArena)
			ihelpuoo.dom.clearAllChildren(this.oArena);
	}
	
	,
	onOK: function()
	{
		ihelpuoo.widget.error.getErrorView().hide();
	}

	// <WEBOO:INHERIT extends="ihelpuoo.widget.View">
	,getElement: function(key){return this.view.getElement(key);}
	,isNeverBeDrawn: function(){return this.view.isNeverBeDrawn();}
	,preparePattern: function(){this.view.preparePattern();}
	// </WEBOO:INHERIT>	
}